package org.dromara.hotel.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.hotel.domain.bo.TerHotelsBo;
import org.dromara.hotel.domain.vo.TerHotelsVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.hotel.domain.vo.TerHotelRoomsVo;
import org.dromara.hotel.domain.bo.TerHotelRoomsBo;
import org.dromara.hotel.service.ITerHotelRoomsService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 酒店房型管理
 * 前端访问路由地址为:/hotel/hotelRooms
 *
 * @author xch
 * @date 2025-06-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/hotelRooms")
public class TerHotelRoomsController extends BaseController {

    private final ITerHotelRoomsService terHotelRoomsService;

    /**
     * 查询酒店房型管理列表
     */
    @SaCheckPermission("hotel:hotelRooms:list")
    @GetMapping("/list")
    public TableDataInfo<TerHotelRoomsVo> list(TerHotelRoomsBo bo, PageQuery pageQuery) {
        return terHotelRoomsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出酒店房型管理列表
     */
    @SaCheckPermission("hotel:hotelRooms:export")
    @Log(title = "酒店房型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TerHotelRoomsBo bo, HttpServletResponse response) {
        List<TerHotelRoomsVo> list = terHotelRoomsService.queryList(bo);
        ExcelUtil.exportExcel(list, "酒店房型管理", TerHotelRoomsVo.class, response);
    }
    @GetMapping("/wechat/queryHome")
    public TableDataInfo<TerHotelRoomsVo> queryHome(PageQuery pageQuery) {
        return terHotelRoomsService.queryHome(pageQuery);
    }

    @GetMapping("/wechat/{hotelId}")
    public TableDataInfo<TerHotelRoomsVo> query(@PathVariable("hotelId") String hotelId,PageQuery pageQuery) {
        return terHotelRoomsService.queryRoomDetail(Long.valueOf(hotelId),pageQuery);
    }

    @GetMapping("/selectComb/{hotelId}")
    public R<List<TerHotelRoomsVo>> list(@PathVariable("hotelId") String hotelId) {
        TerHotelRoomsBo bo = new TerHotelRoomsBo();
        bo.setHotelId(Long.valueOf(hotelId));
        return R.ok(terHotelRoomsService.queryList(bo));
    }
    /**
     * 获取酒店房型管理详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("hotel:hotelRooms:query")
    @GetMapping("/{id}")
    public R<TerHotelRoomsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(terHotelRoomsService.queryById(id));
    }

    /**
     * 新增酒店房型管理
     */
    @SaCheckPermission("hotel:hotelRooms:add")
    @Log(title = "酒店房型管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TerHotelRoomsBo bo) {
        return toAjax(terHotelRoomsService.insertByBo(bo));
    }

    /**
     * 修改酒店房型管理
     */
    @SaCheckPermission("hotel:hotelRooms:edit")
    @Log(title = "酒店房型管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TerHotelRoomsBo bo) {
        return toAjax(terHotelRoomsService.updateByBo(bo));
    }

    /**
     * 删除酒店房型管理
     *
     * @param ids 主键串
     */
    @SaCheckPermission("hotel:hotelRooms:remove")
    @Log(title = "酒店房型管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable("ids") Long[] ids) {
        return toAjax(terHotelRoomsService.deleteWithValidByIds(List.of(ids), true));
    }
}
